/*
 * Created by SharpDevelop.
 * User: Tivadar Papai
 * Date: 8/31/2007
 * Time: 10:45 PM
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */

using System;
using RoverStudio.Common.SysDiagram;
using RoverStudio.Math;
using RoverStudio.Common.Controller;
using RoverStudio.Common.PositionSource;
using System.Drawing;

namespace RoverStudio.Common.WorldModel
{
	/// <summary>
	/// A vehicle representing a real one in the model world.
	/// </summary>
	public class CaterpillarVehicle:PhysicalObject
	{
        private Bitmap roverImage;

        public Bitmap RoverImage
        {
            get { return roverImage; }
            set { roverImage = value; }
        }

        private HighLevelController controllerWater;

        public HighLevelController ControllerWater
        {
            get
            {
                return this.controllerWater;
            }
            set
            {
                this.controllerWater = value;
            }
        }

        private HighLevelController controllerGround;

        public HighLevelController ControllerGround
        {
            get
            {
                return this.controllerGround;
            }
            set
            {
                this.controllerGround = value;
            }
        }

 
        private HighLevelController controller;

        public HighLevelController Controller
        {
            get { return controller; }
            set {
                if (controller != null) //inactivate controller
                    controller.IsActive = false;
                controller = value;
                controller.IsActive = true; //activate controller
            }
        }

        private IPositionSource positionSource;
        public IPositionSource PositionSource
        {
            get
            {
                return positionSource;
            }
            set
            {
                if (positionSource != null)
                    positionSource.PositionUpdated -= new PositionUpdatedHandler(positionSource_PositionUpdated);
                positionSource = value;
                if (positionSource != null)
                    positionSource.PositionUpdated += new PositionUpdatedHandler(positionSource_PositionUpdated);
            }
        }

        void positionSource_PositionUpdated(Vector3D position, Rotation orientation, DateTime time)
        {
            this.SetObjectPositionAndOrientation(position, orientation);
        }

        public CaterpillarVehicle(WorldModel worldModel, string imagePath, string name)
            : base(name, worldModel)
		{
            try
            {
                this.roverImage = new Bitmap(imagePath);
            }
            catch
            {
                this.roverImage = null;
            }
		}

        public CaterpillarVehicle(WorldModel worldModel, string imagePath, string name, Vector3D position, Vector3D diameter, Rotation orientation) :
            base(name, worldModel, position, diameter, orientation)
        {
            try
            {
                this.roverImage = new Bitmap(imagePath);
            }
            catch
            {
                this.roverImage = null;
            }
        
        }
	}
}
